package org.example;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class demoRedisHash {
    public static void test(Jedis jedis){
        System.out.println(" hash");

        jedis.hset("key","field1","111");
        jedis.hset("key","f2","222");
        System.out.println(jedis.hexists("key", "f1"));
        System.out.println(jedis.hexists("key","f2") );
        boolean key = jedis.exists("key");
        System.out.println("   "+key);
        System.out.println(jedis.hdel("key", "f2"));
        System.out.println(jedis.hexists("key", "f2"));

    }

    public static void test1(Jedis jedis){
        System.out.println(" hash");
        jedis.hset("key","field1","111");
        jedis.hset("key","f2","222");
        Set<String> key = jedis.hkeys("key");
        List<String> key1 = jedis.hvals("key");
        System.out.println(key+" " +key1   );
        Map<String,String> map=new HashMap<>();
        map.put("f1","v1");
        map.put("f2","v2");

        jedis.hmset("key1",map  );
        System.out.println(jedis.hmget("key1", "f1", "f2", "f3"));
    }




    public static void main(String[] args) {
        JedisPool jedisPool=new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis=jedisPool.getResource()){
//            test(jedis);
//            test1(jedis);
//            test3(jedis);
            test1(jedis);
        }

    }
}
